home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1760 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  65 lines

  1. Path: hilbert.dnai.com!usenet
  2. From: Victor Bazarov <vbazarov@imsisoft.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Fastest way to index thru an array????
  5. Date: Fri, 12 Jan 1996 11:05:26 -0800
  6. Organization: IMSI
  7. Message-ID: <30F6B0F6.75E3@imsisoft.com>
  8. References: <4d1g3k$o09@solaris.cc.vt.edu> <4d34p7$kj9@tahko.lpr.carel.fi>
  9. NNTP-Posting-Host: vbazarov.imsisoft.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b4a (Win16; I)
  14.  
  15. Ari Lukumies wrote:
  16. > Ashutosh Gokhale <ashutosh> wrote:
  17. > >Suppose I have an array A[][][] which I declare as
  18. > >       double ***A and then assign memory to it using new operator.
  19. > >Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
  20. > >entries of A using[...]
  21. > Try this:
  22. >         double  *p = A;
  23. >         for (i = 0; i < 50*60*70; i++)
  24. >                 *p++ = <some expression>;
  25. >
  26. > BTW, array indexes in C/C++ begin at 0, _not_ at 1.
  27.  
  28. What if he's got to use index to every dimension in <some expression>?
  29.  
  30. Try this:
  31.  
  32. double* ppp = A;
  33. for (i = 0; i < 50; i++)
  34. {
  35.   double* pp = ppp;
  36.   for (j = 0; j < 60; j++)
  37.   {
  38.     double* p = pp;
  39.     for (k = 0; k < 70; k++)
  40.        *p++ = <some expression>;
  41.     pp = p;
  42.   }
  43.   ppp = pp;
  44. }
  45.  
  46. it's definitely slower that one cycle, but will allow to use
  47. i,j,k in <some expression>.
  48.  
  49.  
  50. > Later,
  51. > AriL
  52. > All my opinions are mine and mine alone.
  53.  
  54. Oh yeah!
  55.  
  56. Victor.
  57.  
  58. -- 
  59. Signature.
  60.